<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<%@ page import="xml.response.*"%>
<%@ page import="xml.root"%>
<%@ page import="util.print.printLogCat"%>
<%@ page import="org.sql.table.*"%>
<%@ page import="xml.var"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="jqgrid.jqgrid"%>
<%@ include file="../../util/paramPrint.jsp" %>
<%@ page trimDirectiveWhitespaces="true" %> 
<%   

    /*********** jqgrid ******************/
		jqgrid jq=new jqgrid();
		jq.setRows(request.getParameter(jqgrid._rows));
		jq.setSord(request.getParameter(jqgrid._sord));
		jq.setSortname(request.getParameter(jqgrid._sortname));
		jq.setPage(request.getParameter(jqgrid._page));
		jq.setOper(request.getParameter(jqgrid._oper));
		jq.setSearch(request.getParameter(jqgrid._search));
		/*************************************/
	
		
		String Advice_Title = request.getParameter("Advice_Title");
		String Advice_Type = request.getParameter("Advice_Type");
		String User_ID = request.getParameter("User_ID");
		String UP_ID = request.getParameter("UP_ID");
		String Start_Advice_AddTime = request.getParameter("Start_Advice_AddTime");
		String End_Advice_AddTime = request.getParameter("End_Advice_AddTime");
		String userType=(String)session.getAttribute("User_Type");
		String userID=(String)session.getAttribute("User_ID");
			root root=new root();
		if(userType==null||userID==null||userID.equals("")||userType.equals("")){
		root.setStatus("false");
		root.setMsg("未登录");
		PrintWriter pw = response.getWriter();
		pw.println(root.getXmlString());
		pw.flush();
		return ;
		}
		
	

		adviceinfo1_1 user=new adviceinfo1_1();
		user.setResultField("ID").setResultField("Advice_Title").setResultField("Advice_Type").setResultField("Advice_Content").setResultField("UP_ID").setResultField("User_ID").setResultField("Advice_BackContent").setResultField("BackUser_ID").setResultField("Advice_AddTime").setResultField("Advice_BackTime");
		
		user.setLimit((jq.getPageInt()-1)*jq.getRowsInt(), jq.getRowsInt());
		if(jq.getSortname()!=null&&!jq.getSortname().equals("")){
		user.setOrder(jq.getSortname(),jq.getSord());
		}
		if(Start_Advice_AddTime!=null&&(!Start_Advice_AddTime.equals(""))){
		 user.addequwhile("Advice_AddTime"," >= ",Start_Advice_AddTime);
		}
		if(End_Advice_AddTime!=null&&(!End_Advice_AddTime.equals(""))){
		 user.addequwhile("Advice_AddTime"," <= ",End_Advice_AddTime);
		}
		if(Advice_Title!=null&&(!Advice_Title.equals(""))){
		 user.addequwhile("Advice_Title"," = ",java.net.URLDecoder.decode(Advice_Title,"UTF-8"));
		}
		if(Advice_Type!=null&&(!Advice_Type.equals(""))){
		 user.addequwhile("Advice_Type"," = ",java.net.URLDecoder.decode(Advice_Type,"UTF-8"));
		}
		
		 if(userType!=null&&userType.equals("1")){
			//管理员
		if(UP_ID!=null&&(!UP_ID.equals(""))){
			user.addequwhile("UP_ID"," = ",java.net.URLDecoder.decode(UP_ID,"UTF-8"));
			}
			if(User_ID!=null&&(!User_ID.equals(""))){
			user.addequwhile("User_ID"," = ",java.net.URLDecoder.decode(User_ID,"UTF-8"));
			}	
		}else if(userType!=null&&userType.equals("2")){
			//业务员
			if(User_ID!=null&&(!User_ID.equals(""))){
			 user.addequwhile("User_ID"," = ",User_ID);
				}
			 if(userID!=null&&(!userID.equals(""))){
			 user.addequwhile("UP_ID"," = ",userID);
				}	
		}else if(userType!=null&&userType.equals("3")){
			//客户
			if(userID!=null&&(!userID.equals(""))){
			 user.addequwhile("User_ID"," = ",userID);
				}
			if(UP_ID!=null&&(!UP_ID.equals(""))){
			 user.addequwhile("UP_ID"," = ",UP_ID);
				}	
		}
		
		Vector d=user.getTableFactroy();
		root.setRecords(""+d.size());//设置当前查询到的记录数
		int pageNum=user.getCount()/jq.getRowsInt();
		if((user.getCount()%jq.getRowsInt())>0){
			pageNum++;
		}
		root.setTotal_Count(""+pageNum);//查询到的总记录数
		root.setLimit_Offset(""+jq.getPage());//当前查询页面
		for(int i=0;i<d.size();i++){
			adviceinfo1_1 u=(adviceinfo1_1)d.elementAt(i);
		Enumeration e=u.getTable().elements();
		response res=new response();
		res.setAttribute_Id(""+i);
	for(int j=0;j<u.getResultFieldNum();j++){
			String field=(String)u.getSql().getResultField().elementAt(j);
    		var v=(var)u.getTable().get(field);
    		res.put(v.getName(), v);
		}
		root.addResponse(res);
		}
		//printLogCat.printlnWriter(root.getXmlString());
		String rep=root.getXmlString();
%>
<%=rep%>


